home *** CD-ROM | disk | FTP | other *** search
/ NOVA - For the NeXT Workstation / NOVA - For the NeXT Workstation.iso / Documents / NeXTAnswers / shell.448 < prev    next >
Text File  |  1992-02-06  |  2KB  |  43 lines

  1. {\rtf0\ansi{\fonttbl\f2\fnil Times-Roman;\f0\fmodern Courier;\f1\fswiss Helvetica;}
  2. \paperw11440
  3. \paperh8340
  4. \margl120
  5. \margr120
  6. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\f2\b0\i0\ul0\fs28 shell script csh\
  7. \
  8. Q:  I have a shell script with csh commands (such as 
  9. \f0\b\fs24 set head = $path:h
  10. \f2\b0\fs28 ), but the csh commands don't seem to work.  What could be wrong?
  11. \f1\fs24 \
  12. \
  13.  
  14. \f2\fs28 A:  Did you put \
  15.  
  16. \f0\fs24 \
  17.  
  18. \li720 #! /bin/csh\
  19.  
  20. \f2\fs28\li0 \
  21. at the start of your script?  You probably also want the -f flag (as in 
  22. \f0\b\fs24 #! /bin/csh -f
  23. \f2\b0\fs28 ) so that it doesn't read the invoker's .cshrc file.\
  24. \
  25. The background on this 
  26. \b #! /bin/csh
  27. \b0  stuff has to do with a modification to the kernel loader (the thing that reads in executable programs).  As we recall, this modification came from Berkeley several years ago.\
  28. \
  29. When the loader reads a file that's marked “executable” according to the file's modes (permissions), it examines the first few bytes of the file, looking for a “magic number” — an “integer” which identifies the type of the file.  A Mach-O file, whether an executable or an object file (or a shared library, core file, or preload) will have a four-byte magic number of 0xfeedface.  In old-style UNIX a.out files, the first two bytes specified the machine type, and the second two bytes specified the type of the executable file (OMAGIC, 0407, for old impure; NMAGIC , 0410, for read-only text; ZMAGIC, 0413, for demand-load files).\
  30. \
  31. If the kernel loader sees a “magic number” of 0x2321, it treats the file as an “interpreter file.”  (0x2321 is the hex value of the characters 
  32. \b #!
  33. \b0  in case you were wondering.)  When an interpreter file is found, the remainder of the line following the magic number is examined; the file specified on the remainder of the line is executed, and given the interpreter file as input.  Arguments to the interpreter may be included on that first line.\
  34. \
  35. If the file being executed has the execute bit turned on, but there's no obvious magic number, the Bourne Shell will be used as the interpreter.  This can, indeed, lead to some strange error messages.\
  36. \
  37. QA448            \
  38. \
  39. Valid for 1.0 \
  40. Valid for 2.0\
  41. \
  42.  
  43.